<?xml version="1.0" encoding="utf-8"?>
<xs:schema elementFormDefault="qualified"
           attributeFormDefault="unqualified"
           xmlns:xs="http://www.w3.org/2001/XMLSchema"
           xmlns:cg="http://schemas.microsoft.com/ado/2006/04/codegeneration"
           xmlns:csdl="http://schemas.microsoft.com/ado/2006/04/edm"
           xmlns:ssdl="http://schemas.microsoft.com/ado/2006/04/edm/ssdl"
           xmlns:msl="urn:schemas-microsoft-com:windows:storage:mapping:CS"
           xmlns:edmx="http://schemas.microsoft.com/ado/2007/06/edmx"
           targetNamespace="http://schemas.microsoft.com/ado/2007/06/edmx">

  <xs:annotation>
    <xs:documentation xml:lang="en">
      Entity Data Model Designer Schema
      Copyright (c) Microsoft Corp. All rights reserved.
    </xs:documentation>
  </xs:annotation>

  <xs:import namespace="http://schemas.microsoft.com/ado/2006/04/codegeneration"  schemaLocation="System.Data.Resources.CodeGenerationSchema.xsd" />
  <xs:import namespace="http://schemas.microsoft.com/ado/2006/04/edm/ssdl"        schemaLocation="System.Data.Resources.SSDLSchema.xsd" />
  <xs:import namespace="http://schemas.microsoft.com/ado/2006/04/edm"             schemaLocation="System.Data.Resources.CSDLSchema.xsd" />
  <xs:import namespace="urn:schemas-microsoft-com:windows:storage:mapping:CS"     schemaLocation="System.Data.Resources.CSMSL.xsd"/>

  <xs:element name="Edmx" type="edmx:TEdmx" />

  <xs:complexType name="TEdmx">
    <xs:choice>
      <xs:group ref="edmx:GDesignerFirstGroup" minOccurs="1" maxOccurs="1"/>
      <xs:group ref="edmx:GDesignerLastGroup" minOccurs="1" maxOccurs="1"/>
    </xs:choice>
    <xs:attribute name="Version" type="xs:string" use="required" />
  </xs:complexType>
  
  <!-- GDesignerFirstGroup and GDesignerLastGroup allow us to define the xsd to be order-independent for the designer element & mutually-exclusive runtime & dataservices elements-->
  <xs:group name="GDesignerFirstGroup">
    <xs:sequence>
      <xs:group ref="edmx:GDesignerDataGroup" minOccurs="0"/>
      <xs:group ref="edmx:GRuntimeDataGroup" minOccurs="1"/>
    </xs:sequence>
  </xs:group>

  <xs:group name="GDesignerLastGroup">
    <xs:sequence>
      <xs:group ref="edmx:GRuntimeDataGroup" minOccurs="1"/>
      <xs:group ref="edmx:GDesignerDataGroup" minOccurs="0"/>
    </xs:sequence>
  </xs:group>

  <xs:group name="GRuntimeDataGroup">
    <xs:choice>
      <xs:element name="Runtime" type="edmx:TRuntime" minOccurs="0" maxOccurs="1" />
      <xs:element name="DataServices" type="edmx:TDataServices" minOccurs="0" maxOccurs="1" />
    </xs:choice>
  </xs:group>

  <xs:group name="GDesignerDataGroup">
    <xs:sequence>
      <xs:element name="Designer" type="edmx:TDesigner" minOccurs="0" maxOccurs="1" />
    </xs:sequence>
  </xs:group>

  <xs:complexType name="TDesigner">
    <xs:sequence>
      <xs:element name="Connection" type="edmx:TConnection" minOccurs="0" maxOccurs="1"/>
      <xs:element name="Options" type="edmx:TOptions" minOccurs="0" maxOccurs="1"/>
      <xs:element name="Diagrams" type="edmx:TDiagrams" minOccurs="0" maxOccurs="1"/>
    </xs:sequence>
  </xs:complexType>

  <xs:complexType name="TOptions">
    <xs:sequence>
      <xs:element name="DesignerInfoPropertySet" type="edmx:TDesignerInfoPropertySet" minOccurs="0" maxOccurs="1"/>
    </xs:sequence>
  </xs:complexType>
  <xs:complexType name="TDiagrams">
    <xs:sequence>
      <xs:element name="Diagram" type="edmx:TDiagram" minOccurs="0" maxOccurs="unbounded"/>
    </xs:sequence>
  </xs:complexType>

  <xs:complexType name="TConnection">
    <xs:sequence>
      <xs:element name="DesignerInfoPropertySet" type="edmx:TDesignerInfoPropertySet" minOccurs="0" maxOccurs="1"/>
    </xs:sequence>
  </xs:complexType>

  <xs:complexType name="TDesignerInfoPropertySet">
    <xs:sequence>
      <xs:element name="DesignerProperty" type="edmx:TDesignerProperty" minOccurs="0" maxOccurs="unbounded"/>
    </xs:sequence>
  </xs:complexType>

  <xs:complexType name="TDesignerProperty">
    <xs:attribute name="Name" type="xs:string" use="required" />
    <xs:attribute name="Value" type="xs:string" use="required" />
  </xs:complexType>

  <xs:complexType name="TDiagram">
    <xs:sequence>
      <xs:choice minOccurs="0" maxOccurs="unbounded">
        <xs:element name="EntityTypeShape" type="edmx:TEntityTypeShape" minOccurs="0" maxOccurs="1"/>
        <xs:element name="AssociationConnector" type="edmx:TAssociationConnector" minOccurs="0" maxOccurs="1"/>
        <xs:element name="InheritanceConnector" type="edmx:TInheritanceConnector" minOccurs="0" maxOccurs="1"/>
      </xs:choice>
    </xs:sequence>
    <xs:attribute name="Name" type="xs:string" use="required"/>
    <xs:attribute name="ZoomLevel" type="xs:int" use="optional"/>
    <xs:attribute name="ShowGrid" type="xs:boolean" use="optional"/>
    <xs:attribute name="SnapToGrid" type="xs:boolean" use="optional"/>
    <xs:attribute name="DisplayType" type="xs:boolean" use="optional"/>
  </xs:complexType>

  <xs:complexType name="TEntityTypeShape">
    <xs:attribute name="EntityType" type="xs:string" use="required"/>
    <xs:attribute name="PointX" type="xs:double" use="optional"/>
    <xs:attribute name="PointY" type="xs:double" use="optional"/>
    <xs:attribute name="Width" type="xs:double" use="optional"/>
    <xs:attribute name="Height" type="xs:double" use="optional"/>
    <xs:attribute name="IsExpanded" type="xs:boolean" use="optional"/>
  </xs:complexType>

  <xs:complexType name="TAssociationConnector">
    <xs:sequence>
      <xs:element name="ConnectorPoint" type="edmx:TConnectorPoint" minOccurs="0" maxOccurs="unbounded"/>
    </xs:sequence>
    <xs:attribute name="Association" type="xs:string" use="required"/>
    <xs:attribute name="ManuallyRouted" type="xs:boolean" use="optional"/>
  </xs:complexType>

  <xs:complexType name="TInheritanceConnector">
    <xs:sequence>
      <xs:element name="ConnectorPoint" type="edmx:TConnectorPoint" minOccurs="0" maxOccurs="unbounded"/>
    </xs:sequence>
    <xs:attribute name="EntityType" type="xs:string" use="required"/>
    <xs:attribute name="ManuallyRouted" type="xs:boolean" use="optional"/>
  </xs:complexType>

  <xs:complexType name="TConnectorPoint">
    <xs:attribute name="PointX" type="xs:double" use="required"/>
    <xs:attribute name="PointY" type="xs:double" use="required"/>
  </xs:complexType>

  <xs:complexType name="TRuntime">
    <xs:all>
      <xs:element name="StorageModels" type="edmx:TRuntimeStorageModels" minOccurs="0" maxOccurs="1"/>
      <xs:element name="ConceptualModels" type="edmx:TRuntimeConceptualModels" minOccurs="0" maxOccurs="1"/>
      <xs:element name="Mappings" type="edmx:TRuntimeMappings" minOccurs="0" maxOccurs="1"/>
    </xs:all>
  </xs:complexType>

  <xs:complexType name="TRuntimeConceptualModels">
    <xs:sequence>
      <xs:element ref="csdl:Schema" minOccurs="0" maxOccurs="1"/>
    </xs:sequence>
  </xs:complexType>

  <xs:complexType name="TRuntimeStorageModels">
    <xs:sequence>
      <xs:element ref="ssdl:Schema" minOccurs="0" maxOccurs="1"/>
    </xs:sequence>
  </xs:complexType>

  <xs:complexType name="TRuntimeMappings">
    <xs:sequence>
      <xs:element ref="msl:Mapping" minOccurs="0" maxOccurs="1"/>
    </xs:sequence>
  </xs:complexType>

  <xs:complexType name="TDataServices">
    <xs:sequence>
      <xs:element ref="csdl:Schema" minOccurs="0" maxOccurs="unbounded"/>
    </xs:sequence>
  </xs:complexType>
</xs:schema>
